import requests
from bs4 import BeautifulSoup
import sqlite3

def get_data():
    conn = sqlite3.connect('food.db')
    cursor = conn.cursor()
    try:
        cursor.execute('create table user (name varchar(100) primary key, rl varchar(100))')
    except:
        pass
    # 爬虫获取到食物热量，插入到数据库中。
    for count in range(1, 11):
        for count1 in range(1, 11):
            req = requests.get(r'http://www.boohee.com/food/group/%d?page=%d' % (count, count1))
            res = BeautifulSoup(req.text, "html.parser")
            t = res.find_all('h4')
            t1 = res.find_all('p')
            for i in range(0, len(t)-1):
                a = str(t[i].a.string)
                b = str(t1[i].string)
                try:
                    inse(cursor, a, b)
                    conn.commit()
                except:
                    print('error')
                    pass

    cursor.close()
    conn.close()

def inse(cursor, a, b):
    # 插入数据
    cursor.execute("INSERT OR IGNORE INTO user values(?, ?)", (a, b))

# get_data()
conn = sqlite3.connect('food.db')
cursor = conn.cursor()
# cursor.execute('DELETE from user')
# conn.commit()
t = input()
t = '%'+t+'%'
cursor.execute('SELECT * FROM user WHERE name LIKE ?', (t, ))
for i in cursor:
    print(i[0],i[1])
cursor.close()
conn.close()